package com.pierfrancescosoffritti.androidyoutubeplayer.core.player

class PlayerConstants {

  enum class PlayerState {
    UNKNOWN, UNSTARTED, ENDED, PLAYING, PAUSED, BUFFERING, VIDEO_CUED
  }

  enum class PlaybackQuality {
    UNKNOWN, TINY, SMALL, MEDIUM, LARGE, HD720, HD1080, HIGH_RES, DEFAULT;
    private val QUALITY_TINY = "tiny"
    private val QUALITY_SMALL = "small"
    private val QUALITY_MEDIUM = "medium"
    private val QUALITY_LARGE = "large"
    private val QUALITY_HD720 = "hd720"
    private val QUALITY_HD1080 = "hd1080"
    private val QUALITY_HIGH_RES = "highres"
    private val QUALITY_DEFAULT = "default"

    fun toSString(): String {
      return when (this) {
        UNKNOWN -> QUALITY_DEFAULT
        HD1080 -> QUALITY_HD1080
        HD720 -> QUALITY_HD720
        HIGH_RES -> QUALITY_HIGH_RES
        LARGE -> QUALITY_LARGE
        DEFAULT -> QUALITY_DEFAULT
        SMALL -> QUALITY_SMALL
        TINY -> QUALITY_TINY
        MEDIUM -> QUALITY_MEDIUM
      }
    }
  }

  enum class PlayerError {
    UNKNOWN, INVALID_PARAMETER_IN_REQUEST, HTML_5_PLAYER, VIDEO_NOT_FOUND, VIDEO_NOT_PLAYABLE_IN_EMBEDDED_PLAYER
  }

  enum class PlaybackRate {
    UNKNOWN, RATE_0_25, RATE_0_5, RATE_1, RATE_1_5, RATE_2
  }
}

fun PlayerConstants.PlaybackRate.toFloat(): Float {
  return when (this) {
    PlayerConstants.PlaybackRate.UNKNOWN -> 1f
    PlayerConstants.PlaybackRate.RATE_0_25 -> 0.25f
    PlayerConstants.PlaybackRate.RATE_0_5 -> 0.5f
    PlayerConstants.PlaybackRate.RATE_1 -> 1f
    PlayerConstants.PlaybackRate.RATE_1_5 -> 1.5f
    PlayerConstants.PlaybackRate.RATE_2 -> 2f
  }
}